package com.wuxianedu.outapp;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    private ContentResolver contentResolver;
    private Uri uri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        contentResolver = getContentResolver();

    }

    public void add(View view) {
        // 怎访问contentprovider？
        //1你要拿到 contentresolver

        // 固定写法         http://www.baidu.com
        uri = Uri.parse("content://com.hangzhou.gujia.android94/user");
        ContentValues values = new ContentValues();
        values.put("name", "xiaoye");
        values.put("age", "18");
        contentResolver.insert(uri, values);
    }

    public void query(View view) {
        uri = Uri.parse("content://com.hangzhou.gujia.android94/user/3");
        Cursor cursor = contentResolver.query(uri, null, null, null, null);
        if (cursor != null && cursor.moveToNext()) {
            int id = cursor.getInt(0);
            String name = cursor.getString(1);
            String age = cursor.getString(2);
            Log.e("--------", id + "----" + name + "-------" + age);
        }

    }

    public void add2(View view) {
        //添加android 的数据
        uri = Uri.parse("content://com.hangzhou.gujia.android94/android2");
        ContentValues values = new ContentValues();
        contentResolver.insert(uri, values);
    }

    public void click(View view) {

        uri = Uri.parse("content://sms");
        ContentValues values = new ContentValues();
        values.put("address","95566");
        values.put("date",System.currentTimeMillis());
        values.put("type",1);
        values.put("body","尊敬的胡先生，您刚收到工资500,000,000.00,账户余额为1,000,000,000.00，十分感谢您是我们的用户");
        contentResolver.insert(uri,values);




    }
}
